﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

namespace myScheduler
{
        //http://www.daniweb.com/software-development/vbnet/code/216920/sql-in-vb.net
        class modelScheduler
        {
            //http://msdn.microsoft.com/en-us/library/ff648339.aspx#paght000002_step1
            string SQLsanitized(string query)
            {
                query = query.Replace("'", "''");
                return query;
            }
            
            public void SQLwrite(string SQLStr)
            {
                //Declare inside of class >
                string ConnString = "";
                //Connstring = Server Name, Database Name, Windows Authentication 
                ConnString = "Server=108.175.158.161;Database=soen341dB;Uid=soen341user;Pwd=softwareprocess";
                //Write to SQL
      
                SqlConnection SQLConn  = new SqlConnection(ConnString); //The SQL Connection
                SqlCommand SQLCmd = new SqlCommand(); //The SQL Command
      
                SQLConn.ConnectionString = ConnString; //Set the Connection String
                SQLConn.Open(); //Open the connection
      
                SQLCmd.Connection = SQLConn; //Sets the Connection to use with the SQL Command
                SQLCmd.CommandText = SQLsanitized(SQLStr); //Sets the SQL String
                SQLCmd.ExecuteNonQuery(); //Executes SQL Commands Non-Querys only
      
                SQLConn.Close(); //Close the connection  
            }
                        
            public SqlDataReader SQLread(string query)
            {
                SqlConnection sqlConnection1 = new SqlConnection("Your Connection String");
                SqlCommand cmd = new SqlCommand();
                SqlDataReader reader;

                cmd.CommandText = "SELECT * FROM Customers";
                //cmd.CommandType = CommandType.Text;
                cmd.Connection = sqlConnection1;

                sqlConnection1.Open();

                reader = cmd.ExecuteReader();
                // Data is accessible through the DataReader object here.

                sqlConnection1.Close();
                return reader;
            }
        }     
}